package isdemoenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义常量
const (
	YES int = 1

	NO int = 0
)

// 实现EnumInerface接口
type Isdemo struct {
	enum.Enum[int]
}

// isdemoenum.GetInstance().GetDescMap()
func (e *Isdemo) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		YES: {
			"desc": "是",
		},
		NO: {
			"desc": "否",
		},
	}
}

// instanceCache 存储已经创建的实例
var instanceCache = make(map[int]*Isdemo)

// 根据value获取枚举
func ByValue(value int) *Isdemo {
	if instance, exists := instanceCache[value]; exists {
		return instance
	}
	e := &Isdemo{}
	enum.SetEnumInstance(&e.Enum, e, value)
	instanceCache[value] = e
	return e
}

var Enum *Isdemo = func() *Isdemo {
	e := &Isdemo{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
